Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Diagonal Traverse (medium)
Problem Statement
Given a 2D matrix of size m x n, return a 1D array containing elements of the matrix in the diagonal order.
Example 1:
- Input: `matrix =
[[1,2,3],
[4,5,6]]
- Expected Output:
[1,2,4,5,3,6] - Justification: Traversal begins at 1, moves to 2, diagonally down to 4, up to 5, down to 3, and finally to 6.
Example 2:
- Input: matrix =
[[1,5],
[3,6]]
- Expected Output:
[1,5,3,6] - Justification: The traversal starts from 1, moves to 2, then down to 3, and finally to 4.
Example 3:
- Input: `matrix =
[[1],
[2],
[3]]
- Expected Output:
[1,2,3] - Justification: The traversal is straightforward down the single-column matrix.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Rank Transform of an Array
Solution: Diagonal Traverse
Mark as Completed
On this page
Problem Statement
Example 1:
Example 2:
Example 3:
Try it yourself